﻿using System;
using Facebook;
using ThangNM_LIB.FUNC;

namespace FacebookApp
{
    public partial class GraphApiExplorer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //txtAccessToken.Text = "CAACEdEose0cBAIaJcRwCjLYfZAUFfLdwUZArxGPL5m9W736RZCKshsUOJJUhj3Ph8ZCBc5eIVTAlU12kM4bbOT1MF27zhWZAqOZCdFCU8X1PEqhcmZAArjWCXYPGcii3WtpplZBMfUNrFhCN2xSLaR9clc0K3IYmoiZBNAIZC0Cnt5Ym1ZBxoPHCGZBUfjLZAZBN6lAZBmQ3wPEhTceyQZDZD";
                txtAppId.Text = OtherEx.getAppSettings("Facebook_AppId");
                txtAppSecret.Text = OtherEx.getAppSettings("Facebook_AppSecret");
                ddlVersion.SelectedValue = OtherEx.getAppSettings("Facebook_Version");
                ddlType.SelectedValue = "0";
                txtQuery.Text = "";
            }
        }

        protected void btnGet_Click(object sender, EventArgs e)
        {
            try
            {
                MsgUC1.setClearMsg();
                txtResult.Text = "";
                FacebookClient FBClient = new FacebookClient();
                FBClient.AccessToken = txtAccessToken.Text;
                FBClient.AppId = txtAppId.Text;
                FBClient.AppSecret = txtAppSecret.Text;
                FBClient.Version = ddlVersion.SelectedValue;
                switch (Convert.ToInt16(ddlType.SelectedValue))
                {
                    case ConstEx.Facebook_HttpMethod.Get:
                        txtResult.Text = OtherEx.Facebook_Graph_API_Get(FBClient, txtQuery.Text);
                        break;
                    case ConstEx.Facebook_HttpMethod.Post:
                        txtResult.Text = Convert.ToString(FBClient.Post(txtQuery.Text));
                        break;
                    case ConstEx.Facebook_HttpMethod.Delete:
                        txtResult.Text = Convert.ToString(FBClient.Delete(txtQuery.Text));
                        break;
                    default:
                        txtResult.Text = "";
                        break;
                }
                MsgUC1.setNotifications(ConstEx.FunctionSetMsg.SUCCESS, "OK - " + DateTime.Now.ToString("dd/MM/yyyy - HH:mm:ss"));
            }
            catch (Exception ex)
            {
                MsgUC1.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex);
            }
        }
    }
}